<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <title>dc-example</title>
    <script src="/libs/dc-sdk/dc.min.js"></script>
    <link href="/libs/dc-sdk/dc.min.css" type="text/css" rel="stylesheet" />
    <link href="../index.css" type="text/css" rel="stylesheet" />
  </head>

  <body>
    <div id="viewer-container" class="viewer-container"></div>
    <div class="btn-box">
      <ul>
        <li><button onclick="start()">开始</button></li>
        <li><button onclick="stop()">结束</button></li>
      </ul>
    </div>
    <script>
      DC.config.baseUrl = '../libs/dc-sdk/resources/'
      let viewer = new DC.Viewer('viewer-container')
      let baseLayer = DC.ImageryLayerFactory.createImageryLayer(
        DC.ImageryType.AMAP,
        {
          style: 'img',
          crs: 'WGS84',
        }
      )
      viewer.addBaseLayer(baseLayer, {
        brightness: 0.1,
      })

      let layer = new DC.TilesetLayer('layer').addTo(viewer)
      let tileset = new DC.Tileset(
        '//resource.dvgis.cn/data/3dtiles/ljz/tileset.json'
      )
      let customShader = new DC.CustomShader({
        fragmentShaderText: `
      void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
         vec4 position = czm_inverseModelView * vec4(fsInput.attributes.positionEC,1); // 位置
         float glowRange = 100.0; // 光环的移动范围(高度)
         vec4 temp = vec4(0.2,  0.5, 1.0, 1.0); // 颜色
         temp *= vec4(vec3(position.z / 100.0), 1.0);  // 渐变
         // 动态光环
         float time = fract(czm_frameNumber / 360.0);
         time = abs(time - 0.5) * 2.0;
         float diff = step(0.005, abs( clamp(position.z / glowRange, 0.0, 1.0) - time));
         material.diffuse = vec3(temp.rgb + temp.rgb * (1.0 - diff)) ;
       }
      `,
      })
      tileset.setCustomShader(customShader)
      layer.addOverlay(tileset)
      viewer.flyTo(tileset)

      let aroundPoint = new DC.AroundPoint(
        viewer,
        '121.48914778697578,31.21498411014459',
        { pitch: -41, range: 2000 }
      )

      function start() {
        aroundPoint.start()
      }

      function stop() {
        aroundPoint.stop()
      }
    </script>
  </body>
</html>
